11. MOEA#
import warnings; warnings.simplefilter('ignore')
!wget https://raw.githubusercontent.com/cfteach/modules/master/detector2.py
!pip install pymoo > /dev/null 2>&1
!pip install plotly > /dev/null 2>&1
!pip install ipyvolume > /dev/null 2>&1
!pip install altair > /dev/null 2>&1
--2024-07-10 14:11:37-- https://raw.githubusercontent.com/cfteach/modules/master/detector2.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.110.133, 185.199.111.133, 185.199.108.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7976 (7.8K) [text/plain]
Saving to: ‘detector2.py.4’
detector2.py.4 100%[===================>] 7.79K --.-KB/s in 0.009s
2024-07-10 14:11:37 (863 KB/s) - ‘detector2.py.4’ saved [7976/7976]
%load_ext autoreload
%autoreload 2
import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
#import AI4NP_detector_opt.sol2.detector2 as detector2
import detector2
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.core.problem import Problem
from pymoo.optimize import minimize
from pymoo.visualization.scatter import Scatter
from pymoo.util.display.column import Column
from pymoo.util.display.output import Output
from pymoo.util.nds.non_dominated_sorting import NonDominatedSorting
11.1. Create detector geometry and simulate tracks#
The module detector creates a simple 2D geometry of a wire based tracker made by 4 planes.
The adjustable parameters are the radius of each wire, the pitch (along the y axis), and the shift along y and z of a plane with respect to the previous one.
A total of 8 parameters can be tuned.
The goal of this toy model, is to tune the detector design so to optimize the efficiency (fraction of tracks which are detected) as well as the cost for its realization. As a proxy for the cost, we use the material/volume (the surface in 2D) of the detector. For a track to be detetected, in the efficiency definition we require at least two wires hit by the track.
So we want to maximize the efficiency (defined in detector.py) and minimize the cost.
11.1.1. LIST OF PARAMETERS#
(baseline values)
R = .5 [cm]
pitch = 4.0 [cm]
y1 = 0.0, y2 = 0.0, y3 = 0.0, z1 = 2.0, z2 = 4.0, z3 = 6.0 [cm]
# CONSTANT PARAMETERS
#------ define mother region ------#
y_min=-10.1
y_max=10.1
N_tracks = 1000
print("::::: BASELINE PARAMETERS :::::")
R = 0.5
pitch = 4.0
y1 = 2.0
y2 = 1.0
y3 = 0.0
z1 = 2.0
z2 = 4.0
z3 = 6.0
print("R, pitch, y1, y2, y3, z1, z2, z3: ", R, pitch, y1, y2, y3, z1, z2, z3,"\n")
#------------- GEOMETRY ---------------#
print(":::: INITIAL GEOMETRY ::::")
tr = detector2.Tracker(R, pitch, y1, y2, y3, z1, z2, z3)
Z, Y = tr.create_geometry()
num_wires = detector2.calculate_wires(Y, y_min, y_max)
volume = detector2.wires_volume(Y, y_min, y_max,R)
detector2.geometry_display(Z, Y, R, y_min=y_min, y_max=y_max,block=False,pause=5) #5
print("# of wires: ", num_wires, ", volume: ", volume)
#------------- TRACK GENERATION -----------#
print(":::: TRACK GENERATION ::::")
t = detector2.Tracks(b_min=y_min, b_max=y_max, alpha_mean=0, alpha_std=0.2)
tracks = t.generate(N_tracks)
detector2.geometry_display(Z, Y, R, y_min=y_min, y_max=y_max,block=False, pause=-1)
detector2.tracks_display(tracks, Z,block=False,pause=-1)
#a track is detected if at least two wires have been hit
score = detector2.get_score(Z, Y, tracks, R)
frac_detected = score[0]
resolution = score[1]
print("fraction of tracks detected: ",frac_detected)
print("resolution: ",resolution)
::::: BASELINE PARAMETERS :::::
R, pitch, y1, y2, y3, z1, z2, z3: 0.5 4.0 2.0 1.0 0.0 2.0 4.0 6.0
:::: INITIAL GEOMETRY ::::
# of wires: 21 , volume: 65.94
:::: TRACK GENERATION ::::
fraction of tracks detected: 0.243
resolution: 0.23594329069824552
11.2. Define Objectives#
Defines a class for the objectives of the problem that can be used in the MOO.
# The objectives are computed by setting up the geometry and
# computing the values of the objectives. Mimicing a G4 type simulation
class objectives():
def __init__(self,tracks,y_min,y_max):
self.tracks = tracks
self.y_min = y_min
self.y_max = y_max
def wrapper_geometry(fun):
def inner(self):
R, pitch, y1, y2, y3, z1, z2, z3 = self.X
self.geometry(R, pitch, y1, y2, y3, z1, z2, z3)
return fun(self)
return inner
def update_tracks(self, new_tracks):
self.tracks = new_tracks
def update_design_point(self,X):
self.X = X
def geometry(self,R, pitch, y1, y2, y3, z1, z2, z3):
tr = detector2.Tracker(R, pitch, y1, y2, y3, z1, z2, z3)
self.R = R
self.Z, self.Y = tr.create_geometry()
@wrapper_geometry
def calc_score(self):
res = detector2.get_score(self.Z, self.Y, self.tracks, self.R)
assert res[0] >= 0 and res[1] >= 0,"Fraction or Resolution negative."
return res
def get_score(self,X):
R, pitch, y1, y2, y3, z1, z2, z3 = X
self.geometry(R, pitch, y1, y2, y3, z1, z2, z3)
res = detector2.get_score(self.Z, self.Y, self.tracks, self.R)
return res
def get_volume(self):
volume = detector2.wires_volume(self.Y, self.y_min, self.y_max,self.R)
return volume
res = objectives(tracks,y_min,y_max)
#res.geometry(R, pitch, y1, y2, y3, z1, z2, z3)
X = R, pitch, y1, y2, y3, z1, z2, z3
#fscore = res.get_score(X)
res.update_design_point(X)
fscore = res.calc_score()[0]
fvolume = res.get_volume()
print("...check: ", fvolume, fscore)
...check: 65.94 0.243
11.3. Multi-Objective Optimization#
We will be using pymoo (https://pymoo.org/getting_started.html).
In the constructor method we specify number of variables N, objectives M, and constraint functions, as well as the lower and upper boundaries of each variable. In our toy model, these boundaries are taken in such a way that all solutions are feasible and no constraint function is needed. You can try to change this and introduce some constraint.
The _evaluate method takes a one-dimensional NumPy array x number of entries equal to n_var. This behavior is enabled by setting elementwise_evaluation=True while calling the super() method.
Notice that every function is minimized. Our efficiency is defined as an tracking inefficiency = 1 - efficiency
We add the resolution as a third objective. The average residual of the track hit from the wire centre is used as a proxy for the resolution for this toy-model
from pymoo.core.problem import ElementwiseProblem
class MyProblem(ElementwiseProblem):
#--------- vectorized ---------#
def __init__(self, n_var=8, n_obj=2, n_constr=0,
xl=np.array([0.5,2.5,0.,0.,0.,2.,2.,2.]),
xu=np.array([1.0,5.0,4.,4.,4.,10.,10.,10.])
):
super().__init__(n_var=n_var, n_obj=n_obj, n_constr=n_constr, xl=xl, xu=xu)
def _evaluate(self, x, out, *args, **kwargs):
f1 = 1.- res.get_score(x)[0] # Ineffiency
f2 = res.get_volume() # volume
#f3 = res.get_score(x)[1] #resolution
out["F"] = [f1, f2]#, f3]
11.4. Creation of Problem and choice of optimization algorithm.#
We will use NSGA-II, as explained in the lectures. You can decide the population size and the number of offsprings, based on what we discussed.
Pymoo offers different algorithms that can be used which are highly customizable and can be easily extended. https://pymoo.org/algorithms/index.html
Before dealing with a problem, it’s useful to compare with a list of test problems reported in https://pymoo.org/problems/index.html, where different scenarios in terms of Variables, Objectives, Constraints are described.
n_var = 8 # number of design variables
n_obj = 2 # number of objectives
n_constr = 0 # number of constraints
xl = np.array([0.5,2.5,0.,0.,0.,2.,2.,2.]) # lower bounds of the problem, pitch, diameter, y1, y2, y3, z1, z2, z3
xu = np.array([1.0,5.0,4.,4.,4.,10.,10.,10.]) # upper bounds of the problem, pitch, diameter, y1, y2, y3, z1, z2, z3
pop_size = 40
n_offsprings=10
problem = MyProblem(n_var=n_var, n_obj=n_obj, n_constr=n_constr, xl=xl, xu=xu)
from pymoo.algorithms.moo.nsga2 import NSGA2
from pymoo.operators.crossover.sbx import SBX
from pymoo.operators.mutation.pm import PM
from pymoo.operators.sampling.rnd import FloatRandomSampling
from pymoo.termination import get_termination
from pymoo.termination.xtol import DesignSpaceTermination
from pymoo.termination.robust import RobustTermination
# check out other sampling methods here https://pymoo.org/operators/sampling.html
# check out other crossover methods here https://pymoo.org/operators/crossover.html
algorithm = NSGA2(pop_size=pop_size,n_offsprings=10)
crossover = SBX(prob=1.0, eta=1)
mutation = PM(eta=1)
termination = RobustTermination(DesignSpaceTermination(tol=0.01), period=20)
res = minimize(problem,
algorithm,
crossover = crossover,
mutation = mutation,
termination = termination,
verbose=True,
seed=1,
save_history=True # Saves all of the history of the algorithm
)
Compiled modules for significant speedup can not be used!
https://pymoo.org/installation.html#installation
To disable this warning:
from pymoo.config import Config
Config.warnings['not_compiled'] = False
==========================================================
n_gen | n_eval | n_nds | eps | indicator
==========================================================
1 | 40 | 11 | - | -
2 | 50 | 11 | 0.0027413883 | f
3 | 60 | 12 | 0.0947546531 | ideal
4 | 70 | 12 | 0.0072341683 | f
5 | 80 | 12 | 0.0436893204 | ideal
6 | 90 | 15 | 0.1030478955 | ideal
7 | 100 | 15 | 0.0031563673 | f
8 | 110 | 18 | 0.0063748159 | f
9 | 120 | 20 | 0.0587431694 | ideal
10 | 130 | 21 | 0.0093548023 | f
11 | 140 | 20 | 0.0020407572 | f
12 | 150 | 24 | 0.0072690067 | f
13 | 160 | 24 | 0.0309859155 | nadir
14 | 170 | 26 | 0.0042075736 | ideal
15 | 180 | 30 | 0.0027972028 | ideal
16 | 190 | 34 | 0.0020349296 | f
17 | 200 | 34 | 0.0199714693 | nadir
18 | 210 | 36 | 0.0039945972 | ideal
19 | 220 | 36 | 0.0009826153 | f
20 | 230 | 37 | 0.0037579662 | f
21 | 240 | 35 | 0.0014592392 | f
22 | 250 | 34 | 0.0352112676 | nadir
23 | 260 | 36 | 0.0353260870 | nadir
24 | 270 | 38 | 0.0080862534 | ideal
25 | 280 | 39 | 0.0022170657 | f
26 | 290 | 40 | 0.0039631531 | f
27 | 300 | 40 | 0.0022072120 | f
28 | 310 | 40 | 0.0026901414 | f
29 | 320 | 40 | 0.0001835229 | f
30 | 330 | 39 | 0.0010234613 | f
31 | 340 | 40 | 0.0024187426 | f
32 | 350 | 40 | 0.0940170940 | nadir
33 | 360 | 40 | 0.0023293560 | f
34 | 370 | 38 | 0.0049079755 | nadir
35 | 380 | 37 | 0.0502577320 | nadir
36 | 390 | 36 | 0.0006563741 | f
37 | 400 | 37 | 0.0017141003 | f
38 | 410 | 36 | 0.0028712323 | f
39 | 420 | 38 | 0.0021173840 | f
40 | 430 | 36 | 0.0038759690 | nadir
41 | 440 | 37 | 0.0026562484 | f
42 | 450 | 37 | 0.0002446164 | f
43 | 460 | 37 | 0.0004890469 | f
44 | 470 | 39 | 0.0017601127 | f
45 | 480 | 40 | 0.0065019506 | nadir
46 | 490 | 40 | 0.0004439410 | f
47 | 500 | 39 | 0.0006887275 | f
48 | 510 | 39 | 0.0012391439 | f
49 | 520 | 40 | 0.0023172797 | f
50 | 530 | 40 | 0.0051746442 | ideal
51 | 540 | 40 | 0.0025025970 | f
52 | 550 | 40 | 0.0009235842 | f
53 | 560 | 40 | 0.0008954103 | f
54 | 570 | 40 | 0.0020176739 | f
55 | 580 | 40 | 0.0040757161 | f
56 | 590 | 40 | 0.0004559372 | f
57 | 600 | 40 | 0.0009343304 | f
58 | 610 | 40 | 0.0016153460 | f
59 | 620 | 39 | 0.0032396179 | f
60 | 630 | 40 | 0.0007352798 | f
61 | 640 | 40 | 0.0007373257 | f
62 | 650 | 40 | 0.0016143712 | f
63 | 660 | 40 | 0.0025490394 | f
64 | 670 | 40 | 0.0005419965 | f
65 | 680 | 40 | 0.0010764221 | f
66 | 690 | 40 | 0.0018836599 | f
67 | 700 | 40 | 0.0024873428 | f
68 | 710 | 40 | 0.0032397454 | f
69 | 720 | 40 | 0.0025806452 | ideal
70 | 730 | 40 | 0.0001290855 | f
71 | 740 | 38 | 0.0025740026 | ideal
72 | 750 | 39 | 0.0051746442 | nadir
73 | 760 | 40 | 0.0004228679 | f
74 | 770 | 40 | 0.0006772112 | f
75 | 780 | 40 | 0.0007087106 | f
76 | 790 | 40 | 0.0007733101 | f
77 | 800 | 40 | 0.0017283666 | f
78 | 810 | 40 | 0.0026481686 | f
79 | 820 | 40 | 0.0014715193 | f
80 | 830 | 40 | 0.0020533503 | f
81 | 840 | 40 | 0.0022663095 | f
82 | 850 | 40 | 0.0047945855 | f
83 | 860 | 40 | 0.0012918488 | f
84 | 870 | 40 | 0.0016794457 | f
85 | 880 | 40 | 0.0028232935 | f
86 | 890 | 40 | 0.0005567317 | f
87 | 900 | 40 | 0.0009532404 | f
88 | 910 | 40 | 0.0012762379 | f
89 | 920 | 40 | 0.0017795763 | f
90 | 930 | 40 | 0.0023111541 | f
91 | 940 | 40 | 0.0025372523 | f
92 | 950 | 40 | 0.000000E+00 | f
93 | 960 | 40 | 0.0016059072 | f
94 | 970 | 40 | 0.0028795184 | f
95 | 980 | 40 | 0.0007938843 | f
96 | 990 | 40 | 0.0013896313 | f
97 | 1000 | 40 | 0.0018212966 | f
98 | 1010 | 40 | 0.0021702896 | f
99 | 1020 | 40 | 0.0024489872 | f
100 | 1030 | 40 | 0.0026427857 | f
101 | 1040 | 40 | 0.0003481081 | f
102 | 1050 | 38 | 0.0016148559 | f
103 | 1060 | 40 | 0.0037092973 | f
104 | 1070 | 40 | 0.0006885178 | f
105 | 1080 | 40 | 0.0008242412 | f
106 | 1090 | 40 | 0.0017915888 | f
107 | 1100 | 40 | 0.0019532965 | f
108 | 1110 | 40 | 0.0030048230 | f
109 | 1120 | 40 | 0.0001617076 | f
110 | 1130 | 40 | 0.0003670119 | f
111 | 1140 | 40 | 0.0003670119 | f
112 | 1150 | 40 | 0.0003670119 | f
113 | 1160 | 39 | 0.0005852633 | f
114 | 1170 | 40 | 0.0010142581 | f
115 | 1180 | 40 | 0.0016647951 | f
116 | 1190 | 40 | 0.0031320079 | f
117 | 1200 | 40 | 0.000000E+00 | f
118 | 1210 | 40 | 0.0000659278 | f
119 | 1220 | 40 | 0.0377774021 | nadir
120 | 1230 | 40 | 0.0737878852 | nadir
121 | 1240 | 40 | 0.0016480051 | f
122 | 1250 | 40 | 0.0019964714 | f
123 | 1260 | 40 | 0.0025344208 | f
124 | 1270 | 40 | 0.0005878600 | f
125 | 1280 | 40 | 0.0128018963 | nadir
126 | 1290 | 40 | 0.000000E+00 | f
127 | 1300 | 40 | 0.0006540880 | f
128 | 1310 | 40 | 0.0006540880 | f
129 | 1320 | 40 | 0.0013938250 | f
130 | 1330 | 40 | 0.0104302477 | nadir
131 | 1340 | 40 | 0.0003810035 | f
132 | 1350 | 40 | 0.0050893015 | nadir
133 | 1360 | 40 | 0.0004116133 | f
134 | 1370 | 40 | 0.0008813217 | f
135 | 1380 | 39 | 0.0017824396 | f
136 | 1390 | 39 | 0.0020500669 | f
137 | 1400 | 40 | 0.0204342273 | nadir
138 | 1410 | 40 | 0.0016223997 | f
139 | 1420 | 40 | 0.0016159771 | f
140 | 1430 | 40 | 0.0019855067 | f
141 | 1440 | 40 | 0.0031055978 | f
142 | 1450 | 40 | 0.0000319285 | f
143 | 1460 | 40 | 0.0007717300 | f
144 | 1470 | 40 | 0.0018380253 | f
145 | 1480 | 40 | 0.0032152230 | f
146 | 1490 | 40 | 0.0003831667 | f
147 | 1500 | 40 | 0.0014819364 | f
148 | 1510 | 40 | 0.0013322177 | f
149 | 1520 | 40 | 0.0013322177 | f
150 | 1530 | 40 | 0.0014604268 | f
151 | 1540 | 40 | 0.0014439883 | f
152 | 1550 | 39 | 0.0024449731 | f
153 | 1560 | 39 | 0.0024449731 | f
154 | 1570 | 40 | 0.0025966134 | f
155 | 1580 | 40 | 0.0009963924 | f
156 | 1590 | 40 | 0.0011991239 | f
157 | 1600 | 40 | 0.0011991239 | f
158 | 1610 | 40 | 0.0015260952 | f
159 | 1620 | 40 | 0.0015637512 | f
160 | 1630 | 40 | 0.0033488555 | f
161 | 1640 | 40 | 0.0002064141 | f
162 | 1650 | 40 | 0.0007431454 | f
163 | 1660 | 40 | 0.0007431454 | f
164 | 1670 | 40 | 0.0007432194 | f
165 | 1680 | 40 | 0.0008714189 | f
166 | 1690 | 40 | 0.0008714189 | f
167 | 1700 | 40 | 0.0022613064 | f
168 | 1710 | 40 | 0.0027845635 | f
169 | 1720 | 40 | 0.0003325095 | f
170 | 1730 | 40 | 0.0003325095 | f
171 | 1740 | 40 | 0.0003325095 | f
172 | 1750 | 40 | 0.0168831169 | nadir
173 | 1760 | 40 | 0.0001457224 | f
174 | 1770 | 40 | 0.0006333815 | f
175 | 1780 | 40 | 0.0243074209 | nadir
176 | 1790 | 40 | 0.0039062500 | nadir
177 | 1800 | 40 | 0.0007871277 | f
178 | 1810 | 40 | 0.0007871277 | f
179 | 1820 | 40 | 0.0013405341 | f
180 | 1830 | 40 | 0.0014707636 | f
181 | 1840 | 40 | 0.0018346456 | f
182 | 1850 | 40 | 0.0024717155 | f
183 | 1860 | 40 | 0.0025993989 | f
184 | 1870 | 40 | 0.0006426772 | f
185 | 1880 | 40 | 0.0013358068 | f
186 | 1890 | 40 | 0.0016482430 | f
187 | 1900 | 40 | 0.0018389517 | f
188 | 1910 | 40 | 0.0018715462 | f
189 | 1920 | 40 | 0.0021652485 | f
190 | 1930 | 40 | 0.0023400964 | f
191 | 1940 | 40 | 0.0027679556 | f
192 | 1950 | 40 | 0.000000E+00 | f
193 | 1960 | 40 | 0.0006018343 | f
194 | 1970 | 40 | 0.0008747707 | f
195 | 1980 | 40 | 0.0013667973 | f
196 | 1990 | 40 | 0.0013667973 | f
197 | 2000 | 40 | 0.0016761886 | f
198 | 2010 | 40 | 0.0017413777 | f
199 | 2020 | 40 | 0.0026572064 | f
200 | 2030 | 40 | 0.0000688098 | f
201 | 2040 | 40 | 0.0008445565 | f
202 | 2050 | 40 | 0.0009749648 | f
203 | 2060 | 40 | 0.0014942860 | f
204 | 2070 | 40 | 0.0025934720 | f
205 | 2080 | 40 | 0.0017401394 | f
206 | 2090 | 40 | 0.0023221061 | f
207 | 2100 | 40 | 0.0023872952 | f
208 | 2110 | 40 | 0.0025176733 | f
209 | 2120 | 40 | 0.0004807714 | f
210 | 2130 | 40 | 0.0007745111 | f
211 | 2140 | 40 | 0.0009700783 | f
212 | 2150 | 40 | 0.0013126845 | f
213 | 2160 | 40 | 0.0013452790 | f
214 | 2170 | 40 | 0.0018874618 | f
215 | 2180 | 40 | 0.0018874618 | f
216 | 2190 | 40 | 0.0368806910 | nadir
217 | 2200 | 40 | 0.0004070798 | f
218 | 2210 | 40 | 0.0004746520 | f
219 | 2220 | 40 | 0.0004746520 | f
220 | 2230 | 40 | 0.0004746520 | f
221 | 2240 | 40 | 0.0008422564 | f
222 | 2250 | 40 | 0.0017545221 | f
223 | 2260 | 40 | 0.0020153015 | f
224 | 2270 | 40 | 0.0025819638 | f
225 | 2280 | 40 | 0.0000894849 | f
226 | 2290 | 40 | 0.0026007802 | ideal
227 | 2300 | 40 | 0.0018032340 | f
228 | 2310 | 40 | 0.0018357438 | f
229 | 2320 | 40 | 0.0020486880 | f
230 | 2330 | 40 | 0.0022122668 | f
231 | 2340 | 40 | 0.0031322586 | f
232 | 2350 | 40 | 0.0010404021 | f
233 | 2360 | 40 | 0.0010404021 | f
234 | 2370 | 40 | 0.0014305192 | f
235 | 2380 | 40 | 0.0018711851 | f
236 | 2390 | 40 | 0.0018386788 | f
237 | 2400 | 40 | 0.0026209920 | f
238 | 2410 | 40 | 0.0007648256 | f
239 | 2420 | 40 | 0.0009553363 | f
240 | 2430 | 40 | 0.0009553363 | f
241 | 2440 | 40 | 0.0017599982 | f
242 | 2450 | 40 | 0.0021877392 | f
243 | 2460 | 40 | 0.0021877392 | f
244 | 2470 | 40 | 0.0022591629 | f
245 | 2480 | 40 | 0.0022591629 | f
246 | 2490 | 40 | 0.0650969529 | nadir
247 | 2500 | 40 | 0.0000692521 | f
248 | 2510 | 40 | 0.0010452080 | f
249 | 2520 | 40 | 0.0010452212 | f
250 | 2530 | 40 | 0.0015283975 | f
251 | 2540 | 40 | 0.0022967201 | f
252 | 2550 | 40 | 0.0022967201 | f
253 | 2560 | 40 | 0.0025225513 | f
254 | 2570 | 40 | 0.0004348303 | f
255 | 2580 | 40 | 0.0014622455 | f
256 | 2590 | 40 | 0.0027777778 | nadir
257 | 2600 | 40 | 0.0001908054 | f
258 | 2610 | 40 | 0.0001908054 | f
259 | 2620 | 40 | 0.0011531573 | f
260 | 2630 | 40 | 0.0016783769 | f
261 | 2640 | 40 | 0.0023042212 | f
262 | 2650 | 40 | 0.0024165382 | f
263 | 2660 | 40 | 0.0022032060 | f
264 | 2670 | 40 | 0.0031104250 | f
265 | 2680 | 40 | 0.0006368345 | f
266 | 2690 | 40 | 0.0005684804 | f
267 | 2700 | 40 | 0.0005684804 | f
268 | 2710 | 40 | 0.0010810845 | f
269 | 2720 | 40 | 0.0016093270 | f
270 | 2730 | 40 | 0.0021396112 | f
271 | 2740 | 40 | 0.0022090556 | f
272 | 2750 | 40 | 0.0022090556 | f
273 | 2760 | 40 | 0.0028663403 | f
274 | 2770 | 40 | 0.000000E+00 | f
275 | 2780 | 40 | 0.000000E+00 | f
276 | 2790 | 40 | 0.0005223004 | f
277 | 2800 | 40 | 0.0008139673 | f
278 | 2810 | 40 | 0.0008139673 | f
279 | 2820 | 40 | 0.0008139673 | f
280 | 2830 | 40 | 0.0018244143 | f
281 | 2840 | 40 | 0.0637191157 | nadir
282 | 2850 | 40 | 0.0002857970 | f
283 | 2860 | 40 | 0.0011833511 | f
284 | 2870 | 40 | 0.0012158609 | f
285 | 2880 | 40 | 0.0012158609 | f
286 | 2890 | 40 | 0.0012483706 | f
287 | 2900 | 40 | 0.0013458999 | f
288 | 2910 | 40 | 0.0029587385 | f
289 | 2920 | 40 | 0.000000E+00 | f
290 | 2930 | 40 | 0.0065445026 | nadir
291 | 2940 | 40 | 0.0010669156 | f
292 | 2950 | 40 | 0.0023102327 | f
293 | 2960 | 40 | 0.0033631678 | f
294 | 2970 | 40 | 0.0000786314 | f
295 | 2980 | 40 | 0.0002750071 | f
296 | 2990 | 40 | 0.0010600204 | f
297 | 3000 | 40 | 0.0010600204 | f
298 | 3010 | 40 | 0.0010600204 | f
299 | 3020 | 40 | 0.0014365407 | f
300 | 3030 | 40 | 0.0014692632 | f
301 | 3040 | 40 | 0.0017521710 | f
302 | 3050 | 40 | 0.0019661456 | f
303 | 3060 | 40 | 0.0021627380 | f
304 | 3070 | 40 | 0.0021627380 | f
305 | 3080 | 40 | 0.0021627380 | f
306 | 3090 | 40 | 0.0022132248 | f
307 | 3100 | 40 | 0.0023116020 | f
308 | 3110 | 40 | 0.0024098982 | f
309 | 3120 | 40 | 0.0026720214 | f
310 | 3130 | 40 | 0.0001965924 | f
311 | 3140 | 40 | 0.0039473684 | nadir
312 | 3150 | 40 | 0.0002956075 | f
313 | 3160 | 40 | 0.0008823225 | f
314 | 3170 | 40 | 0.0008823225 | f
315 | 3180 | 40 | 0.0015405343 | f
316 | 3190 | 40 | 0.0015405343 | f
317 | 3200 | 40 | 0.0017206313 | f
318 | 3210 | 40 | 0.0021134568 | f
319 | 3220 | 40 | 0.0021134568 | f
320 | 3230 | 40 | 0.0021134568 | f
321 | 3240 | 40 | 0.0021792462 | f
322 | 3250 | 40 | 0.0027287529 | f
323 | 3260 | 40 | 0.000000E+00 | f
324 | 3270 | 40 | 0.0001197069 | f
325 | 3280 | 40 | 0.0001197069 | f
326 | 3290 | 40 | 0.0009392685 | f
327 | 3300 | 40 | 0.0011037422 | f
328 | 3310 | 40 | 0.0011037422 | f
329 | 3320 | 40 | 0.0011037422 | f
330 | 3330 | 40 | 0.0015740683 | f
331 | 3340 | 40 | 0.0015935613 | f
332 | 3350 | 40 | 0.0017637782 | f
333 | 3360 | 40 | 0.0019294538 | f
334 | 3370 | 40 | 0.0023059640 | f
335 | 3380 | 40 | 0.0028772907 | f
336 | 3390 | 40 | 0.0004946330 | f
337 | 3400 | 40 | 0.0015434352 | f
338 | 3410 | 40 | 0.0017644506 | f
339 | 3420 | 40 | 0.0017644506 | f
340 | 3430 | 40 | 0.0018798936 | f
341 | 3440 | 40 | 0.0018798936 | f
342 | 3450 | 40 | 0.0029230329 | f
343 | 3460 | 40 | 0.0002149308 | f
344 | 3470 | 40 | 0.0002332633 | f
345 | 3480 | 40 | 0.0092961487 | nadir
346 | 3490 | 40 | 0.000000E+00 | f
347 | 3500 | 40 | 0.0004565130 | f
348 | 3510 | 40 | 0.0015263368 | f
349 | 3520 | 40 | 0.0026704886 | f
350 | 3530 | 40 | 0.0000332005 | f
351 | 3540 | 40 | 0.0000462447 | f
352 | 3550 | 40 | 0.0000462447 | f
353 | 3560 | 40 | 0.0000462447 | f
354 | 3570 | 40 | 0.0000462447 | f
355 | 3580 | 40 | 0.0008945736 | f
356 | 3590 | 40 | 0.0012073516 | f
357 | 3600 | 40 | 0.0012134750 | f
358 | 3610 | 40 | 0.0016355172 | f
359 | 3620 | 40 | 0.0026631158 | nadir
360 | 3630 | 40 | 0.0005496998 | f
361 | 3640 | 40 | 0.0010930583 | f
362 | 3650 | 40 | 0.0009781031 | f
363 | 3660 | 40 | 0.0011399979 | f
364 | 3670 | 40 | 0.0011399979 | f
365 | 3680 | 40 | 0.0014143969 | f
366 | 3690 | 40 | 0.0018771532 | f
367 | 3700 | 40 | 0.0018771532 | f
368 | 3710 | 40 | 0.0018782311 | f
369 | 3720 | 40 | 0.0017811649 | f
370 | 3730 | 40 | 0.0022183128 | f
371 | 3740 | 40 | 0.0022183128 | f
372 | 3750 | 40 | 0.0022524937 | f
373 | 3760 | 40 | 0.0023219231 | f
374 | 3770 | 40 | 0.0023219231 | f
375 | 3780 | 40 | 0.0020146673 | f
376 | 3790 | 40 | 0.0020146673 | f
377 | 3800 | 40 | 0.0021545346 | f
378 | 3810 | 40 | 0.0021545346 | f
379 | 3820 | 40 | 0.0025184691 | f
380 | 3830 | 40 | 0.0004660453 | f
381 | 3840 | 40 | 0.0009424448 | f
382 | 3850 | 40 | 0.0009424448 | f
383 | 3860 | 40 | 0.0010090227 | f
384 | 3870 | 40 | 0.0015417986 | f
385 | 3880 | 40 | 0.0015750875 | f
386 | 3890 | 40 | 0.0018634731 | f
387 | 3900 | 40 | 0.0026703535 | f
388 | 3910 | 40 | 0.000000E+00 | f
389 | 3920 | 40 | 0.0000942910 | f
390 | 3930 | 40 | 0.0000942910 | f
391 | 3940 | 40 | 0.0005720457 | f
392 | 3950 | 40 | 0.0007384978 | f
393 | 3960 | 40 | 0.0013709878 | f
394 | 3970 | 40 | 0.0018508980 | f
395 | 3980 | 40 | 0.0024441047 | f
396 | 3990 | 40 | 0.0020723041 | f
397 | 4000 | 40 | 0.0023851478 | f
398 | 4010 | 40 | 0.0027177042 | f
399 | 4020 | 40 | 0.0000332889 | f
400 | 4030 | 40 | 0.0004501224 | f
401 | 4040 | 40 | 0.0004834114 | f
402 | 4050 | 40 | 0.0004834114 | f
403 | 4060 | 40 | 0.0005499893 | f
404 | 4070 | 40 | 0.0010150487 | f
405 | 4080 | 40 | 0.0011428554 | f
406 | 4090 | 40 | 0.0012057996 | f
407 | 4100 | 40 | 0.0012097684 | f
408 | 4110 | 40 | 0.0012097684 | f
409 | 4120 | 40 | 0.0013951153 | f
410 | 4130 | 40 | 0.0013951153 | f
411 | 4140 | 40 | 0.0012644876 | f
412 | 4150 | 40 | 0.0012644876 | f
413 | 4160 | 40 | 0.0017945810 | f
414 | 4170 | 40 | 0.0025779570 | f
415 | 4180 | 40 | 0.000000E+00 | f
416 | 4190 | 40 | 0.000000E+00 | f
417 | 4200 | 40 | 0.0005149009 | f
418 | 4210 | 40 | 0.0012489215 | f
419 | 4220 | 40 | 0.0012822104 | f
420 | 4230 | 40 | 0.0012822104 | f
421 | 4240 | 40 | 0.0014939228 | f
422 | 4250 | 40 | 0.0231607629 | nadir
423 | 4260 | 40 | 0.0082417582 | nadir
424 | 4270 | 40 | 0.0013249670 | f
425 | 4280 | 40 | 0.0014123489 | f
426 | 4290 | 40 | 0.0016414622 | f
427 | 4300 | 40 | 0.0019378640 | f
428 | 4310 | 40 | 0.0041379310 | nadir
429 | 4320 | 40 | 0.0002485656 | f
430 | 4330 | 40 | 0.0006244975 | f
431 | 4340 | 40 | 0.0006244975 | f
432 | 4350 | 40 | 0.0007969113 | f
433 | 4360 | 40 | 0.0010804801 | f
434 | 4370 | 40 | 0.0015284488 | f
435 | 4380 | 40 | 0.0015284488 | f
436 | 4390 | 40 | 0.0016645937 | f
437 | 4400 | 40 | 0.0018763920 | f
438 | 4410 | 40 | 0.0020143230 | f
439 | 4420 | 40 | 0.0030094232 | f
440 | 4430 | 40 | 0.0002766015 | f
441 | 4440 | 40 | 0.0013389243 | f
442 | 4450 | 40 | 0.0015307119 | f
443 | 4460 | 39 | 0.0024431191 | f
444 | 4470 | 40 | 0.0035460569 | f
445 | 4480 | 40 | 0.0000344828 | f
446 | 4490 | 40 | 0.0003103448 | f
447 | 4500 | 40 | 0.0010816217 | f
448 | 4510 | 40 | 0.0010816217 | f
449 | 4520 | 40 | 0.0011161044 | f
450 | 4530 | 40 | 0.0014650275 | f
451 | 4540 | 40 | 0.0018040329 | f
452 | 4550 | 40 | 0.0015281708 | f
453 | 4560 | 40 | 0.0015626536 | f
454 | 4570 | 40 | 0.0015626536 | f
455 | 4580 | 40 | 0.0021219432 | f
456 | 4590 | 40 | 0.0021219432 | f
457 | 4600 | 40 | 0.0022900318 | f
458 | 4610 | 40 | 0.0028647504 | f
459 | 4620 | 40 | 0.0016946470 | f
460 | 4630 | 40 | 0.0016946470 | f
461 | 4640 | 40 | 0.0022474960 | f
462 | 4650 | 40 | 0.0019597009 | f
463 | 4660 | 40 | 0.0020370307 | f
464 | 4670 | 40 | 0.0030387175 | f
465 | 4680 | 40 | 0.0008135850 | f
466 | 4690 | 40 | 0.0010561837 | f
467 | 4700 | 40 | 0.0026045398 | nadir
468 | 4710 | 40 | 0.0005265134 | f
469 | 4720 | 40 | 0.000000E+00 | f
470 | 4730 | 40 | 0.000000E+00 | f
471 | 4740 | 40 | 0.0004267321 | f
472 | 4750 | 40 | 0.0004267321 | f
473 | 4760 | 40 | 0.0004267321 | f
474 | 4770 | 40 | 0.0005644731 | f
475 | 4780 | 40 | 0.0008990480 | f
476 | 4790 | 40 | 0.0011093252 | f
477 | 4800 | 40 | 0.0014691939 | f
478 | 4810 | 40 | 0.0016413702 | f
479 | 4820 | 40 | 0.0018059209 | f
480 | 4830 | 40 | 0.0018403561 | f
481 | 4840 | 40 | 0.0018403561 | f
482 | 4850 | 40 | 0.0023079316 | f
483 | 4860 | 40 | 0.0023079316 | f
484 | 4870 | 40 | 0.0023079316 | f
485 | 4880 | 40 | 0.0024112579 | f
486 | 4890 | 40 | 0.0024112579 | f
487 | 4900 | 40 | 0.0024112579 | f
488 | 4910 | 39 | 0.0111420613 | nadir
489 | 4920 | 40 | 0.0002442044 | f
490 | 4930 | 40 | 0.0002442044 | f
491 | 4940 | 40 | 0.0007486258 | f
492 | 4950 | 40 | 0.0008530826 | f
493 | 4960 | 40 | 0.0008530826 | f
494 | 4970 | 40 | 0.0012709109 | f
495 | 4980 | 40 | 0.0019405596 | f
496 | 4990 | 40 | 0.0020669659 | f
497 | 5000 | 40 | 0.0028277074 | f
498 | 5010 | 40 | 0.0005571034 | f
499 | 5020 | 40 | 0.0005571034 | f
500 | 5030 | 40 | 0.0005571034 | f
501 | 5040 | 40 | 0.0013652274 | f
502 | 5050 | 40 | 0.0015393515 | f
503 | 5060 | 40 | 0.0015393573 | f
504 | 5070 | 40 | 0.0020811082 | f
505 | 5080 | 40 | 0.0026046626 | f
506 | 5090 | 40 | 0.0003588780 | f
507 | 5100 | 40 | 0.0004653687 | f
508 | 5110 | 40 | 0.0002763608 | f
509 | 5120 | 40 | 0.0005557271 | f
510 | 5130 | 40 | 0.0012060635 | f
511 | 5140 | 40 | 0.0018102724 | f
512 | 5150 | 40 | 0.0018102724 | f
513 | 5160 | 40 | 0.0023571587 | f
514 | 5170 | 40 | 0.0023571587 | f
515 | 5180 | 40 | 0.0028713793 | f
516 | 5190 | 40 | 0.000000E+00 | f
517 | 5200 | 40 | 0.0001392758 | f
518 | 5210 | 40 | 0.0004106989 | f
519 | 5220 | 40 | 0.0004106989 | f
520 | 5230 | 40 | 0.0009570934 | f
521 | 5240 | 40 | 0.0009995901 | f
522 | 5250 | 40 | 0.0018372681 | f
523 | 5260 | 40 | 0.0018372681 | f
524 | 5270 | 40 | 0.0018372681 | f
525 | 5280 | 40 | 0.0019874385 | f
526 | 5290 | 40 | 0.0022120527 | f
527 | 5300 | 40 | 0.0027932961 | nadir
528 | 5310 | 40 | 0.0009230703 | f
529 | 5320 | 40 | 0.0011974924 | f
530 | 5330 | 40 | 0.0011974924 | f
531 | 5340 | 40 | 0.0011974924 | f
532 | 5350 | 40 | 0.0011974924 | f
533 | 5360 | 40 | 0.0018062270 | f
534 | 5370 | 40 | 0.0018989338 | f
535 | 5380 | 40 | 0.0019702579 | f
536 | 5390 | 40 | 0.0027063979 | f
537 | 5400 | 40 | 0.0009520265 | f
538 | 5410 | 40 | 0.0009520265 | f
539 | 5420 | 40 | 0.0199430199 | nadir
540 | 5430 | 40 | 0.0000356125 | f
541 | 5440 | 40 | 0.0000356125 | f
542 | 5450 | 40 | 0.0003563977 | f
543 | 5460 | 40 | 0.0007783096 | f
544 | 5470 | 40 | 0.0007783096 | f
545 | 5480 | 40 | 0.0010804174 | f
546 | 5490 | 40 | 0.0011160300 | f
547 | 5500 | 40 | 0.0015706792 | f
548 | 5510 | 40 | 0.0015706792 | f
549 | 5520 | 40 | 0.0020239168 | f
550 | 5530 | 40 | 0.0020239168 | f
551 | 5540 | 40 | 0.0030045177 | f
552 | 5550 | 40 | 0.0005797099 | f
553 | 5560 | 40 | 0.0005797099 | f
554 | 5570 | 40 | 0.0005797099 | f
555 | 5580 | 40 | 0.0011655043 | f
556 | 5590 | 40 | 0.0154277700 | nadir
557 | 5600 | 40 | 0.0000350631 | f
558 | 5610 | 40 | 0.0002375480 | f
559 | 5620 | 40 | 0.0002375480 | f
560 | 5630 | 40 | 0.0008490677 | f
561 | 5640 | 40 | 0.0015304378 | f
562 | 5650 | 40 | 0.0017844976 | f
563 | 5660 | 40 | 0.0028129395 | nadir
564 | 5670 | 40 | 0.000000E+00 | f
565 | 5680 | 40 | 0.0000703561 | f
566 | 5690 | 40 | 0.0003185791 | f
567 | 5700 | 40 | 0.0013539664 | f
568 | 5710 | 40 | 0.0021155088 | f
569 | 5720 | 40 | 0.0171673820 | nadir
570 | 5730 | 40 | 0.0002503577 | f
571 | 5740 | 40 | 0.0004702046 | f
572 | 5750 | 40 | 0.0005351668 | f
573 | 5760 | 40 | 0.0008928206 | f
574 | 5770 | 40 | 0.0011887326 | f
575 | 5780 | 40 | 0.0015122281 | f
576 | 5790 | 40 | 0.0015122281 | f
577 | 5800 | 40 | 0.0021952816 | f
578 | 5810 | 40 | 0.0023025778 | f
579 | 5820 | 40 | 0.0030122771 | f
580 | 5830 | 40 | 0.000000E+00 | f
581 | 5840 | 40 | 0.0001430615 | f
582 | 5850 | 40 | 0.0002861230 | f
583 | 5860 | 40 | 0.0002861230 | f
584 | 5870 | 40 | 0.0002861230 | f
585 | 5880 | 40 | 0.0002861230 | f
586 | 5890 | 40 | 0.0004654802 | f
587 | 5900 | 40 | 0.0004654802 | f
588 | 5910 | 40 | 0.0005017924 | f
589 | 5920 | 40 | 0.0010103436 | f
590 | 5930 | 40 | 0.0011087624 | f
591 | 5940 | 40 | 0.0011445278 | f
592 | 5950 | 40 | 0.0014679670 | f
593 | 5960 | 40 | 0.0021452516 | f
594 | 5970 | 40 | 0.0021452516 | f
595 | 5980 | 40 | 0.0021813218 | f
596 | 5990 | 40 | 0.0026737766 | f
597 | 6000 | 40 | 0.0000357654 | f
598 | 6010 | 40 | 0.0004704675 | f
599 | 6020 | 40 | 0.0004704675 | f
600 | 6030 | 40 | 0.0008416658 | f
601 | 6040 | 40 | 0.0014911945 | f
602 | 6050 | 40 | 0.0015627253 | f
603 | 6060 | 40 | 0.0015627253 | f
604 | 6070 | 40 | 0.0015627253 | f
605 | 6080 | 40 | 0.0015627253 | f
606 | 6090 | 40 | 0.0015627253 | f
607 | 6100 | 40 | 0.0017779036 | f
608 | 6110 | 40 | 0.0018758314 | f
609 | 6120 | 40 | 0.0018758314 | f
610 | 6130 | 40 | 0.0020023538 | f
611 | 6140 | 40 | 0.0020381192 | f
612 | 6150 | 40 | 0.0022169461 | f
613 | 6160 | 40 | 0.0022985792 | f
614 | 6170 | 40 | 0.0027325365 | f
615 | 6180 | 40 | 0.000000E+00 | f
616 | 6190 | 40 | 0.0006403186 | f
617 | 6200 | 40 | 0.0006403186 | f
618 | 6210 | 40 | 0.0006403186 | f
619 | 6220 | 40 | 0.0006403186 | f
620 | 6230 | 40 | 0.0006403186 | f
621 | 6240 | 40 | 0.0006403186 | f
622 | 6250 | 40 | 0.0006403186 | f
623 | 6260 | 40 | 0.0006403186 | f
624 | 6270 | 40 | 0.0006760840 | f
625 | 6280 | 40 | 0.0006760840 | f
626 | 6290 | 40 | 0.0008333410 | f
627 | 6300 | 40 | 0.0008333410 | f
628 | 6310 | 40 | 0.0008333410 | f
629 | 6320 | 40 | 0.0014947267 | f
630 | 6330 | 40 | 0.0017635353 | f
631 | 6340 | 40 | 0.0024243355 | f
632 | 6350 | 40 | 0.0027962960 | f
633 | 6360 | 40 | 0.000000E+00 | f
634 | 6370 | 40 | 0.000000E+00 | f
#print(res.history[0].pop.get("F"))
11.5. Analysis of Results#
import plotly.express as px
fig = px.scatter(res.F, x=0, y=1, labels={'0': 'Efficiency', '1': 'Volume'},
title="In Efficiency vs Volume",
width=800, height=800)
fig.update_traces(marker=dict(size=8,
line=dict(width=1,
color='DarkSlateGrey')),
selector=dict(mode='markers'))
fig.show()
# Making a animation of evolution
import pandas as pd
import plotly.express as px
obj1 = []
obj2 = []
calls = []
for r in res.history:
objs = r.pop.get("F")
obj1.extend(objs[:, 0])
obj2.extend(objs[:, 1])
calls.extend([r.n_gen]*len(objs))
df = pd.DataFrame(data = {"InEfficiency": obj1, "Volume": obj2, "n_gen": calls})
obj_fig = px.scatter(df, x="InEfficiency", y="Volume",
animation_frame="n_gen", color="n_gen",
range_x=[0., 0.6], range_y=[0. , 400.],
hover_data = df.columns,
width = 800, height = 800)
obj_fig.update(layout_coloraxis_showscale=False)
obj_fig.layout.updatemenus[0].buttons[0].args[1]["frame"]["duration"] = 10
obj_fig.update_layout(transition = {'duration': 0.001})
obj_fig.show()
11.6. Exercise#
Can you plot the hypervolume metric to see if the convergence is reached
Can you implement a termination criterion
Plot the optimal configuration of the tracker corresponding to that point
Do analysis of convergence
Visualize the point with a radar or petal diagram, following https://pymoo.org/visualization/index.html